package com.codi.bus.core.service.model;

import com.alibaba.fastjson.annotation.JSONField;
import com.codi.base.domain.BaseDomain;
import com.codi.base.util.BigDecimalUtil;
import com.codi.base.util.DateUtils;
import com.codi.base.util.MoneyUtils;
import com.codi.bus.constant.GlobalConstant;
import lombok.Getter;
import lombok.Setter;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

public class ShareModel extends BaseDomain {

    // 基金代码
    private String fundCode;
    // 份额分类
    private String shareType;
    // 当前份额
    private BigDecimal currentShare;
    // 交易账号
    private String tradeAccount;
    // 可用份额
    private BigDecimal enableShares;
    // 基金冻结数量
    private BigDecimal frozenShare;
    // 分红方式
    private String autoBuy;
    // 交易冻结数量
    private BigDecimal businessFrozenAmount;
    // 未付收益金额
    private BigDecimal unpaidIncome;
    // 资金方式
    private String capitalMode;
    // 银行账号
    private String bankAccount;
    // 每日收益
    private BigDecimal todayIncome;
    // 市值
    private BigDecimal worthValue;
    // 总记录数
    private Long totalCount;
    // 记录数
    private Long rowCount;
    // 可用到期份额
    private BigDecimal availableDueShare;
    // 快速赎回可用份额
    private BigDecimal quickExceedEnableShare;
    // 累计收益
    private BigDecimal accumIncome;
    // 当日申购总额
    private BigDecimal todayApplyTotalQuota;
    // 当日赎回总额
    private BigDecimal todayExceedTotalQuota;
    // 当日转入总额
    private BigDecimal todayTransinTotalQuota;
    // 当日转出总额
    private BigDecimal todayTransoutTotalQuota;
    // 当日赎回转购入总额
    private BigDecimal excetransOutTotalQuota;
    // 当日赎回转购出总额
    private BigDecimal excetransInTotalQuota;
    // 净值
    private BigDecimal netValue;
    // 净值日期
    private Date netValueDate;
    // 基金名字
    private String fundName;
    // 银行名字
    private String bankName;
    // 银行英文简称
    private String bankCode;
    // 持仓收益率
    private BigDecimal accumIncomeRate;
    // 日收益率
    private BigDecimal todayIncomeRate;
    // 万份之收益-10位小数
    private BigDecimal dailyProfit;
    // 本金
    private BigDecimal fundBalance;
    // 基金类型
    private String fundType;
    // 前端基金类型
    private int appFundType;
    /**
     * 成本
     */
    @Setter
    @Getter
    private BigDecimal cost;
    /**
     * 持仓收益
     */
    @Getter
    @Setter
    private BigDecimal shareIncome;
    @Getter
    @Setter
    private BigDecimal totalAccumIncome;
    /**
     * 分红文案
     */
    @Getter
    @Setter
    private String dividends;
    @Setter
    @Getter
    private String taAccount;
    @Setter
    @Getter
    private Integer sellInTransit;
    //联行号
    @Getter
    @Setter
    private String branchBank;
    //支行名称
    @Getter
    @Setter
    private String branchBankName;
    //七日年化
    @Getter
    @Setter
    private String latestWeeklyYield;
    //结转日
    @Getter
    @Setter
    private String clearDate;
    //是否可修改分红方式
    @Getter
    @Setter
    private Boolean canDividend;
    // 基金风险等级
    @Getter
    @Setter
    private Integer riskLevel;
    // 基金风险等级 中文
    @Getter
    @Setter
    private String riskLevelString;
    @Setter
    @Getter
    private List<ShareModel> shareDetails;
    // 基金状态
    @Setter
    @Getter
    private String fundStatus;
    /**
     * 不能分红的弹窗
     */
    @Setter
    @Getter
    private String dividendMethodString;

    public String getFundCode() {
        return this.fundCode;
    }

    public void setFundCode(String fundCode) {
        this.fundCode = fundCode;
    }

    public String getShareType() {
        return this.shareType;
    }

    public void setShareType(String shareType) {
        this.shareType = shareType;
    }

    public BigDecimal getCurrentShare() {
        return this.currentShare;
    }

    public void setCurrentShare(BigDecimal currentShare) {
        this.currentShare = currentShare;
    }

    // 当前份额字符串
    public String getCurrentSharesString() {
        return MoneyUtils.formatMoney(currentShare, 2);
    }

    public String getTradeAccount() {
        return tradeAccount;
    }

    public void setTradeAccount(String tradeAccount) {
        this.tradeAccount = tradeAccount;
    }

    public BigDecimal getEnableShares() {
        return this.enableShares;
    }

    public void setEnableShares(BigDecimal enableShares) {
        this.enableShares = enableShares;
    }

    // 可用份额字符串
    public String getEnableSharesString() {
        return MoneyUtils.formatMoney(enableShares, 2);
    }

    public BigDecimal getFrozenShare() {
        return this.frozenShare;
    }

    public void setFrozenShare(BigDecimal frozenShare) {
        this.frozenShare = frozenShare;
    }

    public String getAutoBuy() {
        return this.autoBuy;
    }

    public void setAutoBuy(String autoBuy) {
        this.autoBuy = autoBuy;
    }

    public BigDecimal getBusinessFrozenAmount() {
        return this.businessFrozenAmount;
    }

    public void setBusinessFrozenAmount(BigDecimal businessFrozenAmount) {
        this.businessFrozenAmount = businessFrozenAmount;
    }

    public BigDecimal getUnpaidIncome() {
        return this.unpaidIncome;
    }

    public void setUnpaidIncome(BigDecimal unpaidIncome) {
        this.unpaidIncome = unpaidIncome;
    }

    // 未付收益金额字符串
    public String getUnpaidIncomeString() {
        return MoneyUtils.formatMoney(this.unpaidIncome, 2);
    }

    public String getCapitalMode() {
        return this.capitalMode;
    }

    public void setCapitalMode(String capitalMode) {
        this.capitalMode = capitalMode;
    }

    public String getBankAccount() {
        return this.bankAccount;
    }

    public void setBankAccount(String bankAccount) {
        this.bankAccount = bankAccount;
    }

    public BigDecimal getTodayIncome() {
        return this.todayIncome;
    }

    public void setTodayIncome(BigDecimal todayIncome) {
        this.todayIncome = todayIncome;
    }

    // 每日收益格式化字符串
    public String getTodayIncomeString() {
        return MoneyUtils.formatMoney(this.todayIncome, 2);
    }

    public BigDecimal getWorthValue() {
        return this.worthValue;
    }

    public void setWorthValue(BigDecimal worthValue) {
        this.worthValue = worthValue;
    }

    // 市值格式化字符串
    public String getWorthValueString() {
        return MoneyUtils.formatMoney(this.worthValue, 2);
    }

    public Long getTotalCount() {
        return this.totalCount;
    }

    public void setTotalCount(Long totalCount) {
        this.totalCount = totalCount;
    }

    public Long getRowCount() {
        return this.rowCount;
    }

    public void setRowCount(Long rowCount) {
        this.rowCount = rowCount;
    }

    public BigDecimal getAvailableDueShare() {
        return this.availableDueShare;
    }

    public void setAvailableDueShare(BigDecimal availableDueShare) {
        this.availableDueShare = availableDueShare;
    }

    public BigDecimal getQuickExceedEnableShare() {
        return this.quickExceedEnableShare;
    }

    public void setQuickExceedEnableShare(BigDecimal quickExceedEnableShare) {
        this.quickExceedEnableShare = quickExceedEnableShare;
    }

    @JSONField(serialize = false)
    public BigDecimal getAccumIncome() {
        return this.accumIncome;
    }

    public void setAccumIncome(BigDecimal accumIncome) {
        this.accumIncome = accumIncome;
    }

    // 累计收益格式化字符串
    public String getAccumIncomeString() {
        return MoneyUtils.formatMoney(this.accumIncome, 2);
    }

    public BigDecimal getTodayApplyTotalQuota() {
        return this.todayApplyTotalQuota;
    }

    public void setTodayApplyTotalQuota(BigDecimal todayApplyTotalQuota) {
        this.todayApplyTotalQuota = todayApplyTotalQuota;
    }

    public BigDecimal getTodayExceedTotalQuota() {
        return this.todayExceedTotalQuota;
    }

    public void setTodayExceedTotalQuota(BigDecimal todayExceedTotalQuota) {
        this.todayExceedTotalQuota = todayExceedTotalQuota;
    }

    public BigDecimal getTodayTransinTotalQuota() {
        return this.todayTransinTotalQuota;
    }

    public void setTodayTransinTotalQuota(BigDecimal todayTransinTotalQuota) {
        this.todayTransinTotalQuota = todayTransinTotalQuota;
    }

    public BigDecimal getTodayTransoutTotalQuota() {
        return this.todayTransoutTotalQuota;
    }

    public void setTodayTransoutTotalQuota(BigDecimal todayTransoutTotalQuota) {
        this.todayTransoutTotalQuota = todayTransoutTotalQuota;
    }

    public BigDecimal getExcetransOutTotalQuota() {
        return this.excetransOutTotalQuota;
    }

    public void setExcetransOutTotalQuota(BigDecimal excetransOutTotalQuota) {
        this.excetransOutTotalQuota = excetransOutTotalQuota;
    }

    public BigDecimal getExcetransInTotalQuota() {
        return this.excetransInTotalQuota;
    }

    public void setExcetransInTotalQuota(BigDecimal excetransInTotalQuota) {
        this.excetransInTotalQuota = excetransInTotalQuota;
    }

    public BigDecimal getNetValue() {
        return this.netValue;
    }

    public void setNetValue(BigDecimal netValue) {
        this.netValue = netValue;
    }

    // 净值字符串
    public String getNetValueString() {
        return MoneyUtils.formatMoney(this.netValue, 4);
    }

    public Date getNetValueDate() {
        return this.netValueDate;
    }

    public void setNetValueDate(Date netValueDate) {
        this.netValueDate = netValueDate;
    }

    // 净值日期字符串 MM-dd
    public String getNetValueDateString() {
        if (this.netValueDate == null) {
            return "";
        }
        return DateUtils.formatDate7(this.netValueDate);
    }

    public String getFundName() {
        return this.fundName;
    }

    public void setFundName(String fundName) {
        this.fundName = fundName;
    }

    public String getBankName() {
        return this.bankName;
    }

    public void setBankName(String bankName) {
        this.bankName = bankName;
    }

    public String getBankCode() {
        return this.bankCode;
    }

    public void setBankCode(String bankCode) {
        this.bankCode = bankCode;
    }

    public BigDecimal getAccumIncomeRate() {
        return this.accumIncomeRate;
    }

    public void setAccumIncomeRate(BigDecimal accumIncomeRate) {
        this.accumIncomeRate = accumIncomeRate;
    }

    // 持仓收益率字符串
    public String getAccumIncomeRateString() {
        if (this.accumIncomeRate != null) {
            return BigDecimalUtil.ConvertToString(this.accumIncomeRate.multiply(new BigDecimal(100))) + "%";
        } else {
            return "";
        }
    }

    public BigDecimal getTodayIncomeRate() {
        return this.todayIncomeRate;
    }

    public void setTodayIncomeRate(BigDecimal todayIncomeRate) {
        this.todayIncomeRate = todayIncomeRate;
    }

    public BigDecimal getDailyProfit() {
        return dailyProfit;
    }

    public void setDailyProfit(BigDecimal dailyProfit) {
        this.dailyProfit = dailyProfit;
    }

    // 万份之收益字符串-货币型基金
    public String getDailyProfitString() {
        if (dailyProfit == null) {
            dailyProfit = new BigDecimal(0);
        }
        return MoneyUtils.formatMoney(dailyProfit, 4);
    }

    // 日收益率字符串
    public String getTodayIncomeRateString() {
        if (this.todayIncomeRate != null) {
            return BigDecimalUtil.ConvertToString(this.todayIncomeRate.multiply(new BigDecimal(100))) + "%";
        } else {
            return "";
        }
    }

    public BigDecimal getFundBalance() {
        return this.fundBalance;
    }

    public void setFundBalance(BigDecimal fundBalance) {
        this.fundBalance = fundBalance;
    }

    // 本金式化字符串
    public String getFundBalanceString() {
        return MoneyUtils.formatMoney(this.fundBalance, 2);
    }

    public String getFundType() {
        return this.fundType;
    }

    public void setFundType(String fundType) {
        this.fundType = fundType;
    }

    public int getAppFundType() {
        return this.appFundType;
    }

    public void setAppFundType(int appFundType) {
        this.appFundType = appFundType;
    }

    // 累计收益格式化字符串
    public String getTotalAccumIncomeString() {
        return MoneyUtils.formatMoney(this.totalAccumIncome, 2);
    }

    public String getSellInTransitString() {
        if (sellInTransit != null && sellInTransit != 0) {
            StringBuffer sb = new StringBuffer();
            sb.append("有");
            sb.append(sellInTransit);
            sb.append("笔赎回确认中");
            return sb.toString();
        }
        return "";
    }

    // 能申购：正常开放，停止赎回，权益登记，红利发放
    public boolean getCanBuy() {
        if (fundStatus == null){
            return true;
        }
        if (fundStatus.equals(GlobalConstant.FUND_BASE_STATUS_OPEN)
            || fundStatus.equals(GlobalConstant.FUND_BASE_STATUS_STOP_SELL)
            || fundStatus.equals(GlobalConstant.FUND_BASE_STATUS_GAIN_REGISTER)
            || fundStatus.equals(GlobalConstant.FUND_BASE_STATUS_DIVIDEND_OFFER)) {
            return true;
        }

        return false;
    }

    // 能赎回：正常开放，停止申购，权益登记，红利发放
    public boolean getCanSell() {
        if (fundStatus == null){
            return true;
        }
        if (fundStatus.equals(GlobalConstant.FUND_BASE_STATUS_OPEN)
            || fundStatus.equals(GlobalConstant.FUND_BASE_STATUS_STOP_BUY)
            || fundStatus.equals(GlobalConstant.FUND_BASE_STATUS_GAIN_REGISTER)
            || fundStatus.equals(GlobalConstant.FUND_BASE_STATUS_DIVIDEND_OFFER)) {
            return true;
        }

        return false;
    }

}
